refactor(@angular/cli): remove resolve dependency and use native require.resolve#32276
refactor(@angular/cli): remove resolve dependency and use native require.resolve#32276clydin merged 2 commits intoangular:mainfrom
Conversation
…ire.resolve This commit removes the `resolve` dependency from `@angular/cli` and replaces its usage with native `require.resolve` via `createRequire`. The `findPackageJson` utility is now only used in migration-only scenarios where the Node.js module caching behavior that prompted the original use of `resolve` is no longer a concern. This reduces the package dependency footprint.
This commit removes the unused `package-tree.ts` utilities, including `getProjectDependencies`, `readPackageJson`, and `PackageTreeNode`. The `findPackageJson` function, which was the only remaining used part, has been moved directly into `commands/update/cli.ts` where it is consumed.
| function findPackageJson(workspaceDir: string, packageName: string): string | undefined { | ||
| try { | ||
| const projectRequire = createRequire(path.join(workspaceDir, 'package.json')); | ||
| const packageJsonPath = projectRequire.resolve(`${packageName}/package.json`); |
There was a problem hiding this comment.
There's a small gotcha for this which is that exports fields can mess with resolving package.json. But 99.9% of the time, an Angular app shouldn't have an exports field (and 90% of the remaining time, people should've added package.json to their exports).
There was a problem hiding this comment.
Packages that contain Angular migrations must have a resolvable package.json so in this specific usage we can luckily avoid that situation.
|
This PR was merged into the repository. The changes were merged into the following branches:
|
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This commit removes the
resolvedependency from@angular/cliand replaces its usage with nativerequire.resolveviacreateRequire. ThefindPackageJsonutility is now only used in migration-only scenarios where the Node.js module caching behavior that prompted the original use ofresolveis no longer a concern. This reduces the package dependency footprint.